package com.villaday.idf.adapter3;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model3.HashStatesEntity;

import java.util.List;

public class HouseManageAdapter extends AbsRecyclerViewAdapter<HashStatesEntity.BodyBean.MonthsBean> {

    public HouseManageAdapter(Context context) {
        super(context, R.layout.recycle_house_manage);
    }


    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HashStatesEntity.BodyBean.MonthsBean d, final int position) {

        holder.bindTextView(R.id.tv_hm_title, d.getYear() + "年" + d.getMonth() + "月");

        RecyclerView rvHmTitle = (RecyclerView) holder.getView(R.id.rv_hm_title);
        rvHmTitle.setLayoutManager(new GridLayoutManager(context, 7));
        HouseManageItemAdapter houseManageItemAdapter = new HouseManageItemAdapter(context);
        houseManageItemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View v, int itemPosition) {
                onRecycleItemClickListener.onItemClick(position, itemPosition);
            }
        });
        rvHmTitle.setAdapter(houseManageItemAdapter);
        

        List<HashStatesEntity.BodyBean.MonthsBean.DaysBean> days = d.getDays();
        int dayOfWeek = days.get(0).getDayOfWeek() == 7 ? 0 : days.get(0).getDayOfWeek();
        for (int i = 0; i < dayOfWeek; i++) {
            HashStatesEntity.BodyBean.MonthsBean.DaysBean daysBean = new HashStatesEntity.BodyBean.MonthsBean.DaysBean();
            daysBean.setText("default");
            days.add(0, daysBean);
        }
        houseManageItemAdapter.setData(days);
    }

    private OnRecycleItemClickListener onRecycleItemClickListener;

    public void setOnRecycleItemClickListener(OnRecycleItemClickListener onRecycleItemClickListener) {
        this.onRecycleItemClickListener = onRecycleItemClickListener;
    }

    public interface OnRecycleItemClickListener {
        void onItemClick(int position, int itemPosition);
    }
}
